package com.pengcheng.taskapplication.mvp.presenter;
import android.app.Activity;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.support.v4.app.Fragment;

import com.pengcheng.taskapplication.contants.ConstantValue;
import com.pengcheng.taskapplication.model.AccountModel;
import com.pengcheng.taskapplication.model.AccountTranModel;
import com.pengcheng.taskapplication.model.AccountVerify;
import com.pengcheng.taskapplication.model.BaseEntity;
import com.pengcheng.taskapplication.model.BaseListEntity;
import com.pengcheng.taskapplication.model.BindCardModel;
import com.pengcheng.taskapplication.model.IcbcValidateModel;
import com.pengcheng.taskapplication.model.IcbcverifySms;
import com.pengcheng.taskapplication.model.IdcardAllOcrModel;
import com.pengcheng.taskapplication.model.PlateNoModel;
import com.pengcheng.taskapplication.model.UserVo;
import com.pengcheng.taskapplication.net.BaseSubscriber;
import com.pengcheng.taskapplication.net.IView;
import com.pengcheng.taskapplication.util.SPUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

/**
 * 任务
 */
public class UserPresenter extends BasePresenter<IView> {
    public Context context;
    public UserPresenter(IView view) {
        super(view);
        if(view instanceof Activity){
            this.context=(Context) view;
        }else{
            this.context=((Fragment)view).getActivity();
        }

    }



    /**
     * 登录接口
     * @param userVo
     * @param type
     */

    public void Login(UserVo userVo, String type) {
        addSubscription(iHttpUrl.login(userVo), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    iView.onFailed(entity.resultCode, entity.msg);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }


    /**
     * 实名认证
     * @param idcardAllOcrModel
     * @param type
     */



    public void realNameAuthV2(IdcardAllOcrModel idcardAllOcrModel, String type) {
        String token = SPUtils.getString(context, ConstantValue.SpType.newtoken);
        String uid = SPUtils.getString(context, ConstantValue.SpType.userid);
        addSubscription(iHttpUrl.checkToken(token,uid), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    addSubscription(iHttpUrl.realNameAuthV2(idcardAllOcrModel), new BaseSubscriber<BaseEntity>(context) {
                        @Override
                        public void onNext(BaseEntity entity) {
                            if (entity.result) {
                                iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                            } else {
                                iView.onFailed(entity.resultCode, entity.msg);
                            }
                        }

                        @Override
                        public void onFailed(String code, String msg) {
                            iView.onFailed(code, msg);
                        }
                    });
                } else {

                }
            }

            @Override
            public void onFailed(String code, String msg) {

            }
        });


    }



    /**
     * 用户认证状态检查
     * @param type
     */

    public void checkCert(String type) {
        addSubscription(iHttpUrl.checkCert(), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    iView.onFailed(entity.resultCode, entity.msg);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }



    /**
     *取消申请接口
     * @param type
     */

    public void cancelApply(long id,String type) {
        addSubscription(iHttpUrl.cancelApply(id), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    iView.onFailed(entity.resultCode, entity.msg);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     *取消申请接口
     * @param type
     */

    public void getQrCode(String code,int size,String type) {
        addSubscription(iHttpUrl.getQrCode(code,size), new BaseSubscriber<ResponseBody>(context) {
            @Override
            public void onNext(ResponseBody value) {
//                byte[] data = new byte[0];
//                try {
//                    data = value.bytes(); //注意：把byte[]转换为bitmap时，也是耗时操作，也必须在子线程
//                    bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
//                    runOnUiThread(new Runnable() {//开启主线程更新UI
//                        @Override
//                        public void run() {
//                            //设置图片到imageview
//                            imageView.setImageBitmap(bitmap);
//                        }
//                    });
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
                iView.onSuccess("2==", "ok", value, type);
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     *发送工行内部短信（工行卡验证）
     * @param icbcValidateModel
     */

    public void sendSms(IcbcValidateModel icbcValidateModel,String type) {
        addSubscription(iHttpUrl.sendSms(icbcValidateModel), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    iView.onFailed(entity.resultCode, entity.msg);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     *工行内部短信验证
     * @param icbcverifySms
     */

    public void verifySms(IcbcverifySms icbcverifySms, String type) {
        addSubscription(iHttpUrl.verifySms(icbcverifySms), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    iView.onFailed(entity.resultCode, entity.msg);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }
    /**
     * 获取开户前信息
     */
    public void openAccountInit(String type) {
        addSubscription(iHttpUrl.openAccountInit(), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    iView.onFailed(entity.resultCode, entity.msg);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }


    /**
     * 开户信息
     */
    public void openAccount(AccountTranModel accountTranModel, String type) {
        addSubscription(iHttpUrl.openAccount(accountTranModel), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    iView.onFailed(entity.resultCode, entity.msg);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 旧认证
     */
    public void idcardFrontReOcr(long  certId, String type) {
        addSubscription(iHttpUrl.idcardFrontReOcr(certId), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    iView.onFailed(entity.resultCode, entity.msg);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }


    /**
     * 旧认证
     */
    public void idcardBackReOcr(long  certId, String type) {
        addSubscription(iHttpUrl.idcardBackReOcr(certId), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    iView.onFailed(entity.resultCode, entity.msg);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }



    /**
     * 工单详细信息
     */
    public void getSubscribeOrder(String code, String type) {
        addSubscription(iHttpUrl.getSubscribeOrder(code), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    iView.onFailed(entity.resultCode, entity.msg);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }


    //上传身份证正面头像文件
    public void idcardFrontOcr(File file, final String type) {
        MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
        RequestBody imageBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
        builder.addFormDataPart("file", file.getName(), imageBody);
        List<MultipartBody.Part> parts = builder.build().parts();
        addSubscription(iHttpUrl.idcardFrontOcr(parts), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    iView.onFailed(entity.resultCode, entity.msg);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    //上传身份证反面头像文件
    public void idcardBackOcr(File file, final String type) {
        MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
        RequestBody imageBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
        builder.addFormDataPart("file", file.getName(), imageBody);
        List<MultipartBody.Part> parts = builder.build().parts();
        addSubscription(iHttpUrl.idcardBackOcr(parts), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    iView.onFailed(entity.resultCode, entity.msg);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }



    /**
     * 发送工行内部短信（工行卡验证）
     */
    public void bindCard(BindCardModel bindCardModel, String type) {
        addSubscription(iHttpUrl.bindCard(bindCardModel), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                }else if(!entity.result&entity.resultCode.equals("2")){
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    iView.onFailed(entity.resultCode, entity.msg);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }

    /**
     * 开户信息验证
     */
    public void openAccountVerify(AccountVerify accountVerify, String type) {
        addSubscription(iHttpUrl.openAccountVerify(accountVerify), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    iView.onFailed(entity.resultCode, entity.msg);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }
    /**
     * 用户电子钱包查询
     请求地址：https://{HOST}/icbc/queryAccount
     */
    public void queryAccount(String type) {
        addSubscription(iHttpUrl.queryAccount(), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    iView.onFailed(entity.resultCode, entity.msg);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }






    /**
     * 申请
     * @param plateNo
     * @param type
     */

    public void apply(PlateNoModel plateNo, String type) {
        String token = SPUtils.getString(context, ConstantValue.SpType.newtoken);
        String uid = SPUtils.getString(context, ConstantValue.SpType.userid);
        addSubscription(iHttpUrl.checkToken(token,uid), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    addSubscription(iHttpUrl.apply(plateNo), new BaseSubscriber<BaseEntity>(context) {
                        @Override
                        public void onNext(BaseEntity entity) {
                            if (entity.result) {
                                iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                            } else {
                                iView.onFailed(entity.resultCode, entity.msg);
                            }
                        }

                        @Override
                        public void onFailed(String code, String msg) {
                            iView.onFailed(code, msg);
                        }
                    });
                } else {

                }
            }

            @Override
            public void onFailed(String code, String msg) {

            }
        });

    }

    /**
     * 是否可申请
     * @param plateNo
     * @param type
     */

    public void isapply(String plateNo, String type) {
        String token = SPUtils.getString(context, ConstantValue.SpType.newtoken);
        String uid = SPUtils.getString(context, ConstantValue.SpType.userid);
        addSubscription(iHttpUrl.checkToken(token,uid), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    addSubscription(iHttpUrl.isApply(plateNo), new BaseSubscriber<BaseEntity>(context) {
                        @Override
                        public void onNext(BaseEntity entity) {
                            if (entity.result) {
                                iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                            } else {
                                iView.onFailed(entity.resultCode, entity.msg);
                            }
                        }

                        @Override
                        public void onFailed(String code, String msg) {
                            iView.onFailed(code, msg);
                        }
                    });
                } else {

                }
            }

            @Override
            public void onFailed(String code, String msg) {

            }
        });

    }


    /**
     * 获取用户信息
     * @param type
     */

    public void getUserDetail(String type) {
        String token = SPUtils.getString(context, ConstantValue.SpType.newtoken);
        String uid = SPUtils.getString(context, ConstantValue.SpType.userid);
        addSubscription(iHttpUrl.checkToken(token,uid), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    addSubscription(iHttpUrl.getUserDetail(), new BaseSubscriber<BaseEntity>(context,false) {
                        @Override
                        public void onNext(BaseEntity entity) {
                            if (entity.result) {
                                iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                            } else {
                                iView.onFailed(entity.resultCode, entity.msg);
                            }
                        }

                        @Override
                        public void onFailed(String code, String msg) {
                            iView.onFailed(code, msg);
                        }
                    });
                } else {

                }
            }

            @Override
            public void onFailed(String code, String msg) {

            }
        });

    }

    /**
     * 获取申请列表
     * @param page
     * @param pageSize
     * @param type
     */

    public void getSubscribes(int page,int pageSize,String type) {
        String token = SPUtils.getString(context, ConstantValue.SpType.newtoken);
        String uid = SPUtils.getString(context, ConstantValue.SpType.userid);
        addSubscription(iHttpUrl.checkToken(token,uid), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    addSubscription(iHttpUrl.getSubscribes(page,pageSize), new BaseSubscriber<BaseListEntity>(context) {
                        @Override
                        public void onNext(BaseListEntity entity) {
                            if (entity.result) {
                                iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                            } else {
                                iView.onFailed(entity.resultCode, entity.msg);
                            }
                        }

                        @Override
                        public void onFailed(String code, String msg) {
                            iView.onFailed(code, msg);
                        }
                    });
                } else {

                }
            }

            @Override
            public void onFailed(String code, String msg) {

            }
        });


    }

    public void getCars(int page,int pageSize,boolean showAll,String type) {
        String token = SPUtils.getString(context, ConstantValue.SpType.newtoken);
        String uid = SPUtils.getString(context, ConstantValue.SpType.userid);
        addSubscription(iHttpUrl.checkToken(token,uid), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    addSubscription(iHttpUrl.getCars(page,pageSize,showAll), new BaseSubscriber<BaseListEntity>(context) {
                        @Override
                        public void onNext(BaseListEntity entity) {
                            if (entity.result) {
                                iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                            } else {
                                iView.onFailed(entity.resultCode, entity.msg);
                            }
                        }

                        @Override
                        public void onFailed(String code, String msg) {
                            iView.onFailed(code, msg);
                        }
                    });
                } else {

                }
            }

            @Override
            public void onFailed(String code, String msg) {

            }
        });

    }


    public void getYuCheBaoSubscribeUrl(String vehicleId,String type) {
        String token = SPUtils.getString(context, ConstantValue.SpType.newtoken);
        String uid = SPUtils.getString(context, ConstantValue.SpType.userid);
        addSubscription(iHttpUrl.checkToken(token,uid), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    addSubscription(iHttpUrl.getYuCheBaoSubscribeUrl(vehicleId), new BaseSubscriber<BaseEntity>(context) {
                        @Override
                        public void onNext(BaseEntity entity) {
                            if (entity.result) {
                                iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                            } else {
                                iView.onFailed(entity.resultCode, entity.msg);
                            }
                        }

                        @Override
                        public void onFailed(String code, String msg) {
                            iView.onFailed(code, msg);
                        }
                    });
                } else {

                }
            }

            @Override
            public void onFailed(String code, String msg) {

            }
        });

    }



    public void getNianJianUrl(String vehicleId,String type) {
        String token = SPUtils.getString(context, ConstantValue.SpType.newtoken);
        String uid = SPUtils.getString(context, ConstantValue.SpType.userid);
        addSubscription(iHttpUrl.checkToken(token,uid), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    addSubscription(iHttpUrl.getNianJianUrl(vehicleId), new BaseSubscriber<BaseEntity>(context) {
                        @Override
                        public void onNext(BaseEntity entity) {
                            if (entity.result) {
                                iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                            } else {
                                iView.onFailed(entity.resultCode, entity.msg);
                            }
                        }

                        @Override
                        public void onFailed(String code, String msg) {
                            iView.onFailed(code, msg);
                        }
                    });
                } else {

                }
            }

            @Override
            public void onFailed(String code, String msg) {

            }
        });

    }


    public void getXSZUrl(String vehicleId,String type) {
        String token = SPUtils.getString(context, ConstantValue.SpType.newtoken);
        String uid = SPUtils.getString(context, ConstantValue.SpType.userid);
        addSubscription(iHttpUrl.checkToken(token,uid), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    addSubscription(iHttpUrl.getXSZUrl(vehicleId), new BaseSubscriber<BaseEntity>(context) {
                        @Override
                        public void onNext(BaseEntity entity) {
                            if (entity.result) {
                                iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                            } else {
                                iView.onFailed(entity.resultCode, entity.msg);
                            }
                        }

                        @Override
                        public void onFailed(String code, String msg) {
                            iView.onFailed(code, msg);
                        }
                    });
                } else {

                }
            }

            @Override
            public void onFailed(String code, String msg) {

            }
        });

    }


    /**
     * 获取验证码接口
     * @param type
     */

    public void getCode(String cellphone, String type) {

        addSubscription(iHttpUrl.getCode(cellphone), new BaseSubscriber<BaseEntity>(context) {
            @Override
            public void onNext(BaseEntity entity) {
                if (entity.result) {
                    iView.onSuccess(entity.resultCode, entity.msg, entity.data, type);
                } else {
                    //iView.onFailed(entity.resultCode, entity.msg);
                    filterCustom(iView,entity);
                }
            }

            @Override
            public void onFailed(String code, String msg) {
                iView.onFailed(code, msg);
            }
        });
    }



    public void filterCustom(IView iView,BaseEntity baseEntity){
        if(baseEntity.resultCode.equals("904")){

        }else{
            iView.onFailed(baseEntity.resultCode,baseEntity.msg);
        }
    }


//    /**
//     * 登录接口
//     * @param userVo
//     * @param type
//     */
//
//    public void get(String type) {
//
//        addSubscription(iHttpUrl.get(), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//    /**
//     * 注册接口
//     * @param type
//     */
//
//    public void regiter(UserRegisterVo userRegisterVo, String type) {
//
//        addSubscription(iHttpUrl.register(userRegisterVo), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//    /**
//     * 修改密码接口
//     * @param type
//     */
//
//    public void updatePassword(UserUpdatePasswordVo userUpdatePasswordVo, String type) {
//
//        addSubscription(iHttpUrl.updatePassword(userUpdatePasswordVo), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//    /**
//     * 个人信息接口
//     * @param type
//     */
//
//    public void getUserInfo(String type) {
//
//        addSubscription(iHttpUrl.getMyInfo(), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//    /**
//     * 绑定支付宝接口
//     * @param type
//     */
//
//    public void updateAlipay(AlipayVo alipayVo, String type) {
//
//        addSubscription(iHttpUrl.updateAlipay(alipayVo), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//    /**
//     * 绑定微信接口
//     * @param type
//     */
//
//    public void updateWX(WechatVo wechatVo, String type) {
//
//        addSubscription(iHttpUrl.updateWechat(wechatVo), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//    /**
//     * 申请提现
//     * @param type
//     */
//
//    public void applayPrice(ApplyPriceVo applyPriceVo, String type) {
//
//        addSubscription(iHttpUrl.applayPrice(applyPriceVo), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//    /**
//     * 获取置顶任务列表接口
//     * @param type
//     */
//
//    public void getTopTaskList(int pageIndex,int pageCount,String type) {
//
//        addSubscription(iHttpUrl.getTopTask(pageIndex,pageCount,"y","1"), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//
//    /**
//     * 获取任务列表接口
//     * @param type
//     */
//
//    public void getSearchFrontTaskList(Long tasktype,String orderparam,String ordertype,String top,int pageIndex,int pageCount,String type) {
//
//        addSubscription(iHttpUrl.getSearchFrontTask(tasktype,orderparam,ordertype,top,pageIndex,pageCount), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//
//    /**
//     * 获取banner
//     * @param type
//     */
//
//    public void getBanner(String type) {
//
//        addSubscription(iHttpUrl.getBannner(), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//
//    /**
//     * 上传图片
//     * @param type
//     */
//
//    public void uploadStepFile(String type) {
//
//        addSubscription(iHttpUrl.getBannner(), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//    //上传头像文件
//    public void uploadStepFile(File file, final String type) {
//        MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
//        RequestBody imageBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
//        builder.addFormDataPart("file", file.getName(), imageBody);
//        List<MultipartBody.Part> parts = builder.build().parts();
//        addSubscription(iHttpUrl.singleuploadfile(parts), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//    }
//
//    /**
//     * 获取任务类型接口
//     * @param type
//     */
//
//    public void getCategory(String type) {
//
//        addSubscription(iHttpUrl.getCategory(), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//    /**
//     * 获取推广排行
//     * @param type
//     */
//
//    public void getInviteList(String monthStatus,String type) {
//
//        addSubscription(iHttpUrl.getInviteList(monthStatus), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//    /**
//     * 获取做单排行
//     * @param type
//     */
//
//    public void getTaskList(String monthStatus,String type) {
//
//        addSubscription(iHttpUrl.getTaskList(monthStatus), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//    /**
//     * 获取任务详情接口
//     * @param type
//     */
//
//    public void getTaskDetail(Long taskid,String type) {
//
//        addSubscription(iHttpUrl.getTaskDetail(taskid), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//    /**
//     * 获取订单详情接口
//     * @param type
//     */
//
//    public void getOrderDetail(Long orderid,String type) {
//
//        addSubscription(iHttpUrl.getOrderDetail(orderid), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//    /**
//     * 审核订单通过
//     * @param type
//     */
//
//    public void passOrder(Long orderid,String type) {
//
//        addSubscription(iHttpUrl.passOrder(orderid), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//    /**
//     * 审核订单不通过
//     * @param type
//     */
//
//    public void unpassOrder(Long orderid,String reason,String type) {
//
//        addSubscription(iHttpUrl.unpassOrder(orderid,reason), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//
//    /**
//     * 领取任务
//     * @param type
//     */
//
//    public void saveOrder(Long taskid,String type) {
//
//        addSubscription(iHttpUrl.saveOrder(taskid), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//    /**
//     * 提交任务
//     * @param type
//     */
//
//    public void commitOrder(CommitOrderVo commitOrderVo, String type) {
//
//        addSubscription(iHttpUrl.commitOrder(commitOrderVo), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//
//
//    /**
//     * 发布任务接口
//     * @param type
//     */
//
//    public void publishTask(TaskVo taskVo, String type) {
//
//        addSubscription(iHttpUrl.publishTask(taskVo), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//    /**
//     * 获取我的任务列表接口
//     * @param type
//     */
//
//    public void getMyTaskList(String is_show,int pageIndex,int pageCount,String type) {
//
//        addSubscription(iHttpUrl.getMyTaskList(is_show,pageIndex,pageCount), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//    /**
//     * 获取我的订单列表接口
//     * @param type
//     */
//
//    public void getMyOrderList(Long  userId,String status,int pageIndex,int pageCount,String type) {
//
//        addSubscription(iHttpUrl.getMyOrderList(userId,status,pageIndex,pageCount), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }
//
//    /**
//     * 获取我发布的任务获取接单列表接口
//     * @param type
//     */
//
//    public void getOrderListByTaskId(Long taskid,String status,int pageIndex,int pageCount,String type) {
//
//        addSubscription(iHttpUrl.getOrderListByTaskId(taskid,status,pageIndex,pageCount), new BaseSubscriber<BaseEntity>(context) {
//            @Override
//            public void onNext(BaseEntity entity) {
//                if ("1000".equals(entity.code)) {
//                    iView.onSuccess(entity.code, entity.message, entity.data, type);
//                } else {
//                    iView.onFailed(entity.code, entity.message);
//                }
//            }
//
//            @Override
//            public void onFailed(String code, String msg) {
//                iView.onFailed(code, msg);
//            }
//        });
//
//    }

}
